<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主订单ID" prop="orderid">
        <el-input
          v-model="queryParams.orderid"
          placeholder="请输入主订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物品类型：1.3C数码 2.家用电器 3.大宗废品" prop="recyclingrestype">
        <el-select v-model="queryParams.recyclingrestype" placeholder="请选择物品类型：1.3C数码 2.家用电器 3.大宗废品" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="物品名称" prop="recyclingresname">
        <el-input
          v-model="queryParams.recyclingresname"
          placeholder="请输入物品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物品规格" prop="specifications">
        <el-input
          v-model="queryParams.specifications"
          placeholder="请输入物品规格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物品重量" prop="recyclingresweight">
        <el-input
          v-model="queryParams.recyclingresweight"
          placeholder="请输入物品重量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预估价格" prop="accpoints">
        <el-input
          v-model="queryParams.accpoints"
          placeholder="请输入预估价格"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态:1.未审核 2.通过 3.驳回 4.免审" prop="auditstatus">
        <el-select v-model="queryParams.auditstatus" placeholder="请选择审核状态:1.未审核 2.通过 3.驳回 4.免审" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="驳回理由" prop="nayreason">
        <el-input
          v-model="queryParams.nayreason"
          placeholder="请输入驳回理由"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间" prop="audittime">
        <el-date-picker clearable size="small"
          v-model="queryParams.audittime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择审核时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否删除：1.未删除 2.已删除" prop="isdel">
        <el-input
          v-model="queryParams.isdel"
          placeholder="请输入是否删除：1.未删除 2.已删除"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="ctime">
        <el-date-picker clearable size="small"
          v-model="queryParams.ctime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['audit:recycling:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['audit:recycling:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['audit:recycling:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['audit:recycling:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recyclingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="详情订单主键" align="center" prop="detailorderid" />
      <el-table-column label="主订单ID" align="center" prop="orderid" />
      <el-table-column label="物品类型：1.3C数码 2.家用电器 3.大宗废品" align="center" prop="recyclingrestype" />
      <el-table-column label="物品名称" align="center" prop="recyclingresname" />
      <el-table-column label="物品规格" align="center" prop="specifications" />
      <el-table-column label="物品重量" align="center" prop="recyclingresweight" />
      <el-table-column label="预估价格" align="center" prop="accpoints" />
      <el-table-column label="图片(多个以逗号分隔)" align="center" prop="pic" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="审核状态:1.未审核 2.通过 3.驳回 4.免审" align="center" prop="auditstatus" />
      <el-table-column label="驳回理由" align="center" prop="nayreason" />
      <el-table-column label="审核时间" align="center" prop="audittime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.audittime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否删除：1.未删除 2.已删除" align="center" prop="isdel" />
      <el-table-column label="创建时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['audit:recycling:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['audit:recycling:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改上门回收审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主订单ID" prop="orderid">
          <el-input v-model="form.orderid" placeholder="请输入主订单ID" />
        </el-form-item>
        <el-form-item label="物品类型：1.3C数码 2.家用电器 3.大宗废品" prop="recyclingrestype">
          <el-select v-model="form.recyclingrestype" placeholder="请选择物品类型：1.3C数码 2.家用电器 3.大宗废品">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="物品名称" prop="recyclingresname">
          <el-input v-model="form.recyclingresname" placeholder="请输入物品名称" />
        </el-form-item>
        <el-form-item label="物品规格" prop="specifications">
          <el-input v-model="form.specifications" placeholder="请输入物品规格" />
        </el-form-item>
        <el-form-item label="物品重量" prop="recyclingresweight">
          <el-input v-model="form.recyclingresweight" placeholder="请输入物品重量" />
        </el-form-item>
        <el-form-item label="预估价格" prop="accpoints">
          <el-input v-model="form.accpoints" placeholder="请输入预估价格" />
        </el-form-item>
        <el-form-item label="图片(多个以逗号分隔)" prop="pic">
          <el-input v-model="form.pic" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核状态:1.未审核 2.通过 3.驳回 4.免审">
          <el-radio-group v-model="form.auditstatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="驳回理由" prop="nayreason">
          <el-input v-model="form.nayreason" placeholder="请输入驳回理由" />
        </el-form-item>
        <el-form-item label="审核时间" prop="audittime">
          <el-date-picker clearable size="small"
            v-model="form.audittime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否删除：1.未删除 2.已删除" prop="isdel">
          <el-input v-model="form.isdel" placeholder="请输入是否删除：1.未删除 2.已删除" />
        </el-form-item>
        <el-form-item label="创建时间" prop="ctime">
          <el-date-picker clearable size="small"
            v-model="form.ctime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecycling, getRecycling, delRecycling, addRecycling, updateRecycling } from "@/api/audit/recycling";

export default {
  name: "Recycling",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 上门回收审核表格数据
      recyclingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderid: null,
        recyclingrestype: null,
        recyclingresname: null,
        specifications: null,
        recyclingresweight: null,
        accpoints: null,
        pic: null,
        auditstatus: null,
        nayreason: null,
        audittime: null,
        isdel: null,
        ctime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderid: [
          { required: true, message: "主订单ID不能为空", trigger: "blur" }
        ],
        recyclingrestype: [
          { required: true, message: "物品类型：1.3C数码 2.家用电器 3.大宗废品不能为空", trigger: "change" }
        ],
        recyclingresname: [
          { required: true, message: "物品名称不能为空", trigger: "blur" }
        ],
        specifications: [
          { required: true, message: "物品规格不能为空", trigger: "blur" }
        ],
        auditstatus: [
          { required: true, message: "审核状态:1.未审核 2.通过 3.驳回 4.免审不能为空", trigger: "blur" }
        ],
        isdel: [
          { required: true, message: "是否删除：1.未删除 2.已删除不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询上门回收审核列表 */
    getList() {
      this.loading = true;
      listRecycling(this.queryParams).then(response => {
        this.recyclingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        detailorderid: null,
        orderid: null,
        recyclingrestype: null,
        recyclingresname: null,
        specifications: null,
        recyclingresweight: null,
        accpoints: null,
        pic: null,
        remark: null,
        auditstatus: 0,
        nayreason: null,
        audittime: null,
        isdel: null,
        ctime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.detailorderid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加上门回收审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const detailorderid = row.detailorderid || this.ids
      getRecycling(detailorderid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改上门回收审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.detailorderid != null) {
            updateRecycling(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecycling(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const detailorderids = row.detailorderid || this.ids;
      this.$confirm('是否确认删除上门回收审核编号为"' + detailorderids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delRecycling(detailorderids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('audit/recycling/export', {
        ...this.queryParams
      }, `audit_recycling.xlsx`)
    }
  }
};
</script>